<?php
#
# author: Phil Spagnolo
# (c)2008 South Hill Calvary Chapel
#

function bible1year_table ($result, $num_rows) {

  $header = array("Date","Old Testament","New Testament");
  table_header($header, NULL);

  $i=0;
  while ($i < $num_rows) {
    $date=mysql_result($result,$i,"date");
    $php_time = strtotime($date);
    $xml_date = date("F jS", $php_time);

    $OT=mysql_result($result,$i,"OT");
    $NT=mysql_result($result,$i,"NT");

    $row = array($xml_date, $OT,$NT); 
    table_row($row, row_class($i+1), NULL);
    $i++;
  }
  table_footer(3);
}

$linkList = array("Bible1year.php",
            "Bible1year.php?X=Q1","Bible1year.php?X=Q2","Bible1year.php?X=Q3","Bible1year.php?X=Q4");
$textList = array("Current", "Jan/Feb/Mar", "Apr/May/Jun", "Jul/Aug/Sept", "Oct/Nov/Dec");

include_once("./root.inc.php");
include_once("${root}/common.php");
include("${root}/mysql/database_info.php");
include("${root}/mysql/common.php");

$table = "Bible1YearNew";
connect_select_test($table);

$now = time();

if (isset($_GET['X'])) {
	$X = $_GET['X'];
	if ($X!='Q1' && $X!='Q2' && $X!='Q3' && $X!='Q4' && $X!='intro') {
		die ("Error:  Bad input '$X' must be Q1, Q2, Q3, or Q4");
	} 
} else {
	//get current month
	$m = date('n',$now);
	if ($m < 4) {$X='Q1';}
	else if ($m < 7) {$X='Q2';}
	else if ($m < 10) {$X='Q3';}
	else {$X='Q4';}
}

$title = "Read Thru the Bible in One Year";
$meta_key='Bible, reading, one, 1, year, plan, daily, scripture, annually, annual';
$meta_desc="A plan to read through the Bible in one year.";
print_html_head($title ,$meta_key,$meta_desc);

print_java_head(NULL);
begin_body();

printf("<style type='text/css'>table {width: 90%%;}</style>\n");

page_title_no_content("Today's Bible Reading:");
printf("<div class='content'>\n");
$todaysReading = mysql_query("SELECT * FROM `Bible1YearNew` WHERE `date` LIKE '%".date("m-d")."' ");
bible1year_table ($todaysReading, 1);
printf("</div>\n");
printf("<h2 class='page_title'>Archive:</h2><br>\n");
in_page_link(5, false, $linkList, $textList, NULL);

switch ($X) {
	case 'Q1':
		printf("<H4>January, February, March</H4><br>\n");
		$x=1;	$y=$x+1;$z=$y+1;
		$query="SELECT * FROM $table WHERE (MONTH(date)='$x' OR MONTH(date)='$y' OR MONTH(date)='$z') ORDER BY date ASC";
		break;
	case 'Q2':
		printf("<H4>April, May, June</H4><br>\n");
		$x=4;	$y=$x+1;$z=$y+1;
		$query="SELECT * FROM $table WHERE (MONTH(date)='$x' OR MONTH(date)='$y' OR MONTH(date)='$z') ORDER BY date ASC";
		break;
	case 'Q3':
		printf("<H4>July, August, September</H4><br>\n");
		$x=7;	$y=$x+1;$z=$y+1;
		$query="SELECT * FROM $table WHERE (MONTH(date)='$x' OR MONTH(date)='$y' OR MONTH(date)='$z') ORDER BY date ASC";
		break;
	default:
		printf("<H4>October, November, December</H4><br>\n");
		$x=10;	$y=$x+1;$z=$y+1;
		$query="SELECT * FROM $table WHERE (MONTH(date)='$x' OR MONTH(date)='$y' OR MONTH(date)='$z') ORDER BY date ASC";
		break;
}

$result=mysql_query($query) or die (mysql_error());
$num_rows=mysql_num_rows($result);
printf("<div class='content'>\n");
bible1year_table($result, $num_rows);
printf("</div>\n");

in_page_link(5, false, $linkList, $textList, NULL);

end_page_title();
end_body();
?>
